package com.deyuanyun.pic.pig.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.deyuanyun.pic.common.util.UploadUtil;
import com.deyuanyun.pic.pig.domain.CleanPipeLineManagerVo;
import com.deyuanyun.pic.pig.domain.EvluationVO;
import com.deyuanyun.pic.pig.domain.PigResults;
import com.deyuanyun.pic.pig.domain.PigTask;
import com.deyuanyun.pic.pig.mapper.PigResultsMapper;
import com.deyuanyun.pic.pig.mapper.PigTaskMapper;
import com.deyuanyun.pic.pig.mapper.PigTaskPointMapper;
import com.deyuanyun.pic.pig.service.CleanPipeLineHistoryService;
import com.deyuanyun.pic.pig.util.PiggingUtil;

@Service
public class CleanPipeLineHistoryServiceImpl implements CleanPipeLineHistoryService {
	@Resource
	private PigTaskMapper pigTaskMapper;
	@Resource
	private PigTaskPointMapper pigTaskPointMapper;
	@Resource
	private PigResultsMapper pigResultsMapper;
	
	@Override
	public List getCleanPipeLineHistoryIndex(CleanPipeLineManagerVo vo) {
		return pigTaskMapper.getCleanPipeLineHistoryIndex(vo);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Map<String,Object> getDetail(String taskId,Map<String, Object> map) {
			PigResults pigResult = pigResultsMapper.getDetail(taskId);
			map.put("pigResult", pigResult);
			//该任务对应的跟踪点通过记录
			List markPoint = null;
			String reverse = pigTaskMapper.selectReverseByTaskId(taskId);
			if(!StringUtils.isEmpty(reverse)){
				Map<String,Object> reMap = new HashMap<String,Object>();
				reMap.put("taskId", taskId);
				reMap.put("reverse", reverse);
				markPoint = pigTaskPointMapper.getInspTaskPointByTaskId(reMap);
			}
			map.put("markPoint", markPoint);
			//获取任务名称，收发点
			CleanPipeLineManagerVo c = pigTaskPointMapper.getPigByTaskId(taskId);
			//照片
			String fileUrl = UploadUtil.SOURCE + UploadUtil.IMGURL;
			List imgList =  PiggingUtil.searchImg(fileUrl, taskId,null, false, true);
			map.put("other", c);
			map.put("taskId",taskId);
			map.put("imgList", imgList);
			map.put("fileUrl", fileUrl);
		return map;
	}

	
	
	public static float mmTopx(float mm){
	     mm = (float) (mm *3.33) ;
	     return mm ;
	    }

	@Override
	public Map<String, Object> getDetailData(Map<String, Object> o,String taskId, String resourcePath,String imgPath) {
		o.put("resourcePath", resourcePath);
		PigTask task = pigTaskMapper.selectByPrimaryKey(taskId);
		o.put("task", task);
		CleanPipeLineManagerVo cleanType = pigTaskMapper.getcleanTypeByTypeId(task.getType());
		o.put("cleanType", cleanType);
		PigResults pigResult = pigResultsMapper.getDetail(taskId);
		o.put("pigResult", pigResult);
		//该任务对应的跟踪点通过记录
		List markPoint = null;
		String reverse = pigTaskMapper.selectReverseByTaskId(taskId);
		if(!StringUtils.isEmpty(reverse)){
			Map<String,Object> reMap = new HashMap<String,Object>();
			reMap.put("taskId", taskId);
			reMap.put("reverse", reverse);
			markPoint = pigTaskPointMapper.getInspTaskPointByTaskId(reMap);
		}
		o.put("markPoint", markPoint);
		//获取任务名称，收发点
		CleanPipeLineManagerVo c = pigTaskPointMapper.getPigByTaskId(taskId);
		o.put("other", c);
		//照片
		List imgList =  PiggingUtil.searchImg(imgPath, taskId,null, false, true);
		o.put("imgList", imgList);
		return o;
	}

	@Override
	public Map<String, Object> goEvluation(String ids,Map<String, Object> map) {
		List<String> idArr = new ArrayList<String>();
		String[] idArrs = ids.split(",");
//		Arrays.asList(a)
		for (String id : idArrs) {
			idArr.add(id);
		}
		map.put("para", idArr);
		EvluationVO headValue = pigTaskMapper.getHeadValue(map);
		List<EvluationVO> listValue = pigTaskMapper.getListValue(map);
		map.put("headValue", headValue);
		map.put("listValue", listValue);
		return map;
	}

}
